<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="zh-cn">
    <head>
        <!-- Bootstrap -->
        <include file="Include/css" />
        <title>中经汇通</title>
        <!--编辑器--->
        <link type="text/css"  rel="stylesheet" href="__STATICS__/js/um/themes/default/css/umeditor.css" >
        <link href="__STATICS__/css/admin/index.css" rel="stylesheet">
        <link href="__STATICS__/css/sweet-alert.css" rel="stylesheet">
        <script type="text/javascript" src="__STATICS__/js/sweet-alert.min.js"></script>
    </head>

    <body>
        <include file="Include/nav_top" />
        <div class="container clearfix" id="left_menu_wraper" >
            <include  file="Include/menu_left" />
            <div id="right-content">
                <div id="right-content-inner">
                    <ul class="breadcrumb">
                        <span>您的位置：</span>
                        <li><a href="{:U('Houtai/Index/index')}">首页</a> </li>
                        <li class="">广告管理</li>
                        <li class="active">图文素材列表</li>
                    </ul>
                    <p>
                        <button id="add_look" class="btn btn-orange" type="button" data-id="2" >
                            添加图文素材
                        </button>
                    </p>
                    <div role="tabpanel">

                        <div class="row clearfix margin10 form-horizontal">
                                    <form  name="query" method="POST" >
                                        <span class="pull-left ml30 form_bar">搜索条件：</span>
                                        <div class="col-md-2">
                                            <input type="text" name="sTitle" value="{$Think.request.sTitle}" placeholder=" 标题" class="pull-left ml10 form-control" />
                                        </div>
                                        <button type="submit" class="pull-left btn btn-default ml20">
                                            搜索
                                        </button>
                                    </form>
                                    
                                </div>

                                <table class="table ">
                                    <thead class="table_head">
                                        <tr class="border">
                                            <th>编号</th>
                                            <th>标题</th>
											<th>封面图片</th>
                                            <th>添加时间</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <volist name="list" id="vo">
                                            <tr class="qr_tar">
                                                <td>
                                                    {$vo['materialID']}
                                                </td>
                                                <td>
                                                   {$vo.title} 
                                                </td>
                                                <td class="list_img"><img src="{$imgDomain}{$vo.img}" data-thumb="{$imgDomain}{$vo.img}" width="226px" height="138px" ></img></td>
                                                <td>{$vo['addtime'] | date="Y/m/d H:i:s",###} </td>
                                                <td data-id="{$vo.materialID}" >
                                                    <a href="javascript:void(0);" class="edit_look" >编辑</a>
                                                    /
                                                    <a href="javascript:void(0);" class="tar_delete" >删除</a> 
                                                </td>
                                            </tr>
                                        </volist>
                                    </tbody>
                                </table>

                                <div class="clearfix s_page pull-right">
                                    {$page}
                                </div>
                            </div>

                    </div>

                </div>

            </div>
        
        <!-- 基本信息 Modal - 开始 -->
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="myModalLabel"> </h4>
                    </div>
                    <div class="modal-body">
                        <div role="tabpanel" class="tab-pane active" id="home">

                            <div class="row clearfix">
                                <div class="col-md-12 margin10">
                                    <div class="col-md-2 text_right form_bar">
                                                    标题：
                                    </div>
                                    <div class="col-md-7">
                                            <input id="title" type="text" class="form-control"/>
                                    </div>
                                    <div class="col-md-2 text_warning text_left form_bar">
                                                    * 建议100字内
                                    </div>
                                </div>
                                
                                
                                <div class="col-md-12 margin10">
                                    <div class="col-md-2 text_right form_bar">
                                        封面图片：
                                    </div>
                                    <div class="col-md-7">
                                        <div class="upload_wraper dash clearfix" style="width:200px;height:200px;">
                                            <img src="__STATICS__/images/upload_comn.png" class=" col-xs-12" id="pic" alt=""/>
                                            <input type="file" class="input_file" id="fileupload" name="file" value="" data-url="" multiple=""/>
                                        </div>
                                    </div>
                                    <div class="col-md-2 text_warning text_left form_bar">
                                        *
                                    </div>
                                </div>
                                
                                
                                <div class="col-md-12 margin10">
                                    <div class="col-md-2 text_right form_bar">
                                        链接
                                    </div>
                                    <div class="col-md-7">
                                        <input id="url" type="text" class="form-control" placeholder="" readonly="readonly"/>
                                    </div>
                                    <div class="col-md-2 text_warning text_left form_bar">
                                        首次保存后自动生成不可编辑
                                    </div>
                                </div>

                                
                                <div class="col-md-12 margin10" id="addContent" >
                                    <div class="col-md-2 text_right form_bar">
                                                    正文：
                                    </div>
                                    <div class="col-md-10">
                                        <textarea id="content" ></textarea>
                                    </div>
                                </div>
                            </div>
                                    <input type="hidden" id="materialID" />
                        </div>

                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-primary" id="save" >保存</button>
                    </div>
                </div>
            </div>
        </div><!-- 基本信息 Modal - 结束 -->
        
        <include file="Include/script" />
        <script src="__STATICS__/js/bootstrap-editable.min.js"></script>
        
        <!--编辑器-->
        <script type="text/javascript" charset="utf-8" src="__STATICS__/js/um/umeditor.config.js"></script>
        <script type="text/javascript" charset="utf-8" src="__STATICS__/js/um/umeditor.min.js"></script>
        <script type="text/javascript" src="__STATICS__/js/jquery.ui.widget.js"></script>
        <script type="text/javascript" src="__STATICS__/js//jquery.iframe-transport.js"></script>
        <script type="text/javascript" src="__STATICS__/js/jquery.fileupload.js"></script>
        <script type="text/javascript" src="__STATICS__/js/jquery-form.js"></script>
        <script type="text/javascript" src="__STATICS__/js/upload_base.js"></script>
        <script type="text/javascript" src="__STATICS__/js/um/lang/zh-cn/zh-cn.js"></script>
                
       <script>
            var isReload = false; // 标识弹出框关闭之后是否刷新页面
            var myDom; // 当前操作的dom对象
            var img_url="__STATICS__/images";
            var um = UM.getEditor('content',{ initialFrameWidth:'100%' });
            var headImgUrl = "{:U('CNEPAdmin/Upload/uploadImg/pathType/6')}";
            /*菜单展开及高亮*/
            $(function () {
                $('.slideImg').addClass('open');
                $('#slideImg3').addClass('active');

                /*基本信息的弹出框隐藏后*/
                $('#myModal').on('hidden.bs.modal', function (e) {
                     reset_display();
                });
                
                /*编辑*/
                $(".edit_look").on("click", function () {
                    var self = $(this);
                    var materialID = self.closest("td").attr("data-id");
// um.setContent(arr.content);
                    var ajaxData = {};
                    ajaxData.materialID = materialID;
                    ajax_go_1(ajaxData,"{:U('CNEPAdmin/Material/edit')}",onEdit);
                    
                });
                
                function onEdit(rsp) {
                    if(rsp.result > 0) {
                        var arr = rsp.arr;
                        $("#title").val(arr.title);
                        $("#materialID").val(arr.materialID);
                        $("#pic").attr('src',arr.img);
                        $("#url").val(arr.url);
                        $("#myModalLabel").html("编辑(添加时间:"+ arr.addtime +")");
						um.setContent(arr.content);
                        $('#myModal').modal(); // 跳出弹窗
                    } else {
                        swal("操作失败;" + rsp.desc,"","error");
                    }
                }
                
                /*删除弹窗*/
                $(".tar_delete").on("click", function () {
                    var self = $(this);
                    swal({   title: "您确定吗?",
                                text: "您将删除此图文素材，用户将不再可见！",
                                type: "warning",
                                showCancelButton: true,
                                confirmButtonColor: "#DD6B55",
                                confirmButtonText: "是的，删除",
                                cancelButtonText: "放弃",
                                closeOnConfirm: false
                            },
                            function (isConfirm) {
                                if (isConfirm) {
                                    var ajaxData = {};
                                    ajaxData.materialID = self.closest('td').attr('data-id');
                                    ajax_go_1(ajaxData ,'deleteMaterial', onDel); // 参数1：提交的json数据；参数2:请求的地址；参数3：回调方法
                                }

                            });
                });
                /* rsp 即服务端返回的json */
                function onDel(rsp) {
                    if(rsp.result > 0) {
                        window.location.reload();
                    } else {
                        swal("操作失败",'',"error");
                    }
                }



                /*添加时候弹窗*/
                $("#add_look").on("click", function() {
                    $("#myModalLabel").html("添加图文素材");
                    $('#myModal').modal(); // 跳出弹窗
                });
                
                /*点击保存*/
                $("#save").on("click", function () {
                    var rt = true;
                                        
                    var title = $.trim($("#title").val());
                    var materialID = $.trim($("#materialID").val());
                    var content = um.getContent();
                    var img = $('#pic').attr('src');
					var url = $('#url').val();
                    if(title === '')
                    {   
                        rt = false;
                        $('#title').focus();
                        swal('请为消息拟好标题','','warning');
                    }
                    
                    if(rt) {
                        var ajaxData ={}; // json 类

                        ajaxData.title = title;
						ajaxData.content = content;
						if(img!='/statics/images/upload_comn.png'){
                        	ajaxData.img = img;
                        }
						ajaxData.url = url;

                        if(materialID > 0)
                            ajaxData.materialID = materialID;
                        
                        console.log(ajaxData);
                        //return;
                         ajax_go_1(ajaxData ,"{:U('CNEPAdmin/Material/saveMaterial')}",onSave);
                    } else {
                        return rt;
                    }
                    
                });
                
                function onSave(rsp) {
                    if(rsp.result > 0) {
                        swal("操作成功","","success");
                        window.location.reload();
                    } else {
                        swal("操作失败;"+rsp.desc,"","error");
                    }
                }
                
                /*清空弹出框内容*/
                function reset_display()
                {
                    if(isReload) {
                        window.location.reload();
                    }
					$("#pic").attr("src","");
                    $("#title").val("");
					$("#url").val("");
                    $("#materialID").val("");
                    um.setContent("");
                }

                /* 上传主图 */
                upload_img_1(headImgUrl,'fileupload',function(data){
                    if(data.result > 0) {
                        $('#fileupload').attr('data-id',data.path);
                        $("#pic").attr("src", data.path);
                    } else {
                        swal("网络出错","","error");
                    }
                });/*第一个参数：上传图片的路径,第二个参数：file_input标签id,第三个参数：回调函数*/
                
               

            });
                        
        </script>
    </body>
</html>